const Koa = require('koa');
const app = new Koa();

function delay(ctx) {
    return Promise.resolve({
        then: (resolve) => {
            setTimeout(() => {
                ctx.body += '3';
                resolve();
            }, 3000);
        },
    });
}

app.use(async (ctx, next) => {
    ctx.body = '1';
    await next();
    ctx.body += '5';
});

app.use(async (ctx, next) => {
    ctx.body += '2';
    await next();
    ctx.body += '4';
});

app.use(async (ctx, next) => {
    await delay(ctx);
});

app.listen(3000, () => {});
